package com.thoughtworks.tax.strategy;

import java.math.BigDecimal;

import com.thoughtworks.tax.Item;

/**
 * This class define the sales tax compute stratgy template.
 * @author Tang Ling
 */
public abstract class SalesTaxStrategy
{
	protected static final BigDecimal	FACTOR			= new BigDecimal("0.05");
	protected static final BigDecimal	SALES_TAX		= new BigDecimal("10");
	protected static final BigDecimal	IMPORTED_TAX	= new BigDecimal("5");
	protected static final BigDecimal	DIV_FACROT		= new BigDecimal("100");

	/**
	 * Caculdate the item tax and return it ,the return value has been rounded up to the nearest 0.05
	 * @param item
	 * @return
	 */
	public BigDecimal getSalesTax(Item item)
	{
		BigDecimal saleTax = caculdateTax(item);
		saleTax = saleTax.divide(FACTOR);
		saleTax = new BigDecimal(Math.ceil(saleTax.doubleValue()));
		saleTax = saleTax.multiply(FACTOR);
		return saleTax;
	}

	/**
	 * define the tax caculating method , this method is implemented by the actually strategy
	 * @param item
	 * @return
	 */
	protected abstract BigDecimal caculdateTax(Item item);

}
